package com.core.cloudcommon.redis.enums;

/**
 * @author =====Lqj=====
 * @className CloudRedisTemplateResuitCode
 * @description
 * @create 2024/11/18 12:39
 **/

public enum CloudRedisTemplateResultCode {

    CODE300001(300001, "缓存key不能为空，请检查"),
    CODE300002(300002, "缓存value不能为空，请检查"),
    CODE300003(300003, "请求参数不能为空，请检查");


    private final Integer code;
    private final String msg;

    CloudRedisTemplateResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // 获取 code 值
    public Integer getCode() {
        return code;
    }

    // 获取 msg 值
    public String getMsg() {
        return msg;
    }

    /**
     * 通过 code 获取枚举项
     */
    public static CloudRedisTemplateResultCode getByCode(Integer code) {
        if (code == null) {
            throw new IllegalStateException("响应编码不能为空");
        }
        for (CloudRedisTemplateResultCode resultCode : CloudRedisTemplateResultCode.values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        throw new IllegalStateException("编码不存请重试输入,不存在的编码：" + code);
    }
}
